function index_ = taskRingEstimate(varargin)
% A simple task with a FP and ring and dots with random dir of motion.
%   Use ASL for saccades to the ring.

% graphics
diam = 5;
arg_dXtarget = { ...
    'diameter',     {.3,    .1, diam+10}, ...
    'cmd',          {0,     0,  1}};

arg_dXdots = { ...
    'diameter',     diam, ...
    'direction',    0, ...
    'density',      40, ...
    'speed',        10};

% hardwares
BF.n = 5;
BF.lowP = 0;
BF.deltaP = 10;
BF.deltaH = 650;
BF.deltaV = 650;
arg_dXasl = { ...
    'mouseMode',    true, ...
    'freq',         120, ...
    'blinkParams',  BF, ...
    'aslRect',      [-2032, 1532, 4064, -3064], ...
    'showPlot',     true, ...
    'showPtr',      {{'dXdots'};{'dXtarget'}}};

arg_dXsound = { ...
    'mute',         false, ...
    'rawSound',     'Coin.wav'};

% query maps
acquire = { ...
    'dXkbHID',  {'any', 'error'}; ...
    'dXasl',    {[1,true,inf], 'hold', true}};
hold = { ...
    'dXkbHID',  {'any', 'error'}; ...
    'dXasl',    {[1,false,inf], 'acquire', true}};
settle = { ...
    'dXkbHID',  {'any', 'error'}; ...
    'dXasl',    {[2,false,inf], 'acquire', true}};
resp = { ...
    'dXkbHID',  {'any', 'error'}; ...
    'dXasl',    {[2,false,inf], 'ok', true}};

% state function and argument shorthand
GS = @rGraphicsShow;
tgs = {'dXtarget', 1:2};
fp = {'dXtarget', 1};
dt = {'dXdots', 1};
ndt = {{},dt{:}};
nfp = {{},fp{:}};

CT = @centerTargetOnFixation;
ctf = {2, 300, 'diameter2', 2};

SP = @rPlay;
cash = {'dXsound', 1};

% an anonymous function for randomizing dot direction
RD = @() rSet('dXdots', 1, 'direction', rand*360);

%   name        fun args        jump    wait    repsDrawQuery   cond
arg_dXstate = {{ ...
    'clear',    {}, {},         'next', 0,      0,  5,  0,      {}; ...
    'indicate', GS, tgs,        'next', 0,      0,  3,  0,      {}; ...
    'acquire',  {}, {},         'error',3e4,    0,  0   acquire,{}; ...
    'hold',     {}, {},         'next', 350,    0,  0,  hold,   {}; ...
    'recenter', CT, ctf,        'next', 0,      0,  0,  1,      {}; ...
    'settle',   {}, {},         'next', 1000,   0,  0,  settle, {}; ...
    ...
    'gap',      GS, nfp,        'next', 200,    0,  3,  1,      {}; ...
    'nextStim',	RD, {},         'next', 0,      0,  0,  1,      {}; ...
    'showStim', GS, dt,         'error',100,    0,  1,  {},     {}; ...
    'respond',  GS, ndt,        'error',500,    0,  3,  resp,   {}; ...
    ...
    'ok',       SP, cash,       'end',  500,    0,  0,  0,      {}; ...
    'error',    {}, {},         'end',  500,	0,  5,  0,      {}; ...
    'end',      {}, {},         'x',    0,      0,  5,  0,      {}; ...
    }};
sz = size(arg_dXstate{1}, 1);

arg_dXtask = { ...
    'statesToFIRA', { ...
        'clear',    3; ...
        'indicate', 3; ...
        'acquire',  1; ...
        'hold',     1; ...
        'settle',   1; ...
        'gap',      3; ...
        'showStim', 3; ...
        'respond',  3; ...
        'ok',       1; ...
        'error',    3; ...
        'end',      3; ...
        }, ...
    'wrtState',         'showStim', ...
    'objectsToFIRA',    {'saveToFIRA'}, ...
    'anyStates',        {'ok'}, ...
    'bgColor',          [0,0,0], ...
    'trialOrder',       'random', ...
    'showFeedback',     false, ...
    'timeout',          3600};

helper = {'current', false, true, false};
name = mfilename;
index_ = rAdd('dXtask', 1, {'root', false, true, false}, ...
    'name',         name(5:end), ...
    'timeLimit',    5*60, ...
    'helpers',      { ...
        'dXtarget',     3,  helper,	arg_dXtarget; ...
        'dXdots',       1,  helper,	arg_dXdots; ...
        'dXasl',        1,  helper,	arg_dXasl; ...
        'dXsound',      1,  helper,	arg_dXsound; ...
        'dXstate',      sz, helper, arg_dXstate; ...
        }, ...
    arg_dXtask{:}, varargin{:});
